const http = require("./utils/http")

// app.js
App({
  onLaunch(changjingzhi2) {
    // 展示本地存储能力
    const changjingzhi = wx.getLaunchOptionsSync();
    // console.log("场景值", changjingzhi);

    // console.log("启动参数", changjingzhi2);

    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        // console.log("登陆", res.code)
        // 发送后给后台，进行数据交互

        // 给后台发送请求获取用户的主键
        this.globalData.js_code = res.code;
        http.get({
            url: "index/getUserOpenId",
            data: {js_code: res.code},
            successCallback: (res) => {
                this.globalData.pk_user = res.data.pk_user
            },
            errorCallback: function(err) {
                console.log(err);
            }
        })
      }
    })
  },
  globalData: {
    userInfo: null,
    pk_user: null,
    js_code: null
  }
})
